package tds.model28;
/**
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName Client
 * @Description 解释器模式使用-解析特殊字符为音符
 * @author tds
 * @Date 2020/2/8 18:40
 * @version 1.0.0
 */
public class Client {
    public static void main(String[] args) {
        // 当首字母是O时，则表达式实例化为音阶；其他实例化为音符
        PlayContext context = new PlayContext();

        Expression expression = null;

        // 需要解释的文本
        String text = "O 2 E 0.5 A 3 E 4 ";
        context.setText(text);

        while (context.getText().length() > 0){
            String str = context.getText().substring(0, 1);
            switch (str){
                case "O":
                    expression = new Scale();
                    break;
                case "C":
                case "D":
                case "E":
                case "F":
                case "G":
                case "A":
                case "B":
                case "P":
                    expression = new Note();
            }
            expression.interpret(context);
        }

    }
}
